import 'package:flutter/painting.dart';
import 'package:pp_uikit/theme/pp_default_theme.dart';

/// 标签配置类
class PPTagTheme {
  PPTagTheme({
    TextStyle? tagTextStyle,
    TextStyle? selectTagTextStyle,
    double? tagRadius,
    Color? tagBackgroundColor,
    Color? selectedTagBackgroundColor,
    double? tagHeight,
    double? tagWidth,
    double? tagMinWidth,
  })  : _tagTextStyle = tagTextStyle,
        _selectTagTextStyle = selectTagTextStyle,
        _tagRadius = tagRadius,
        _tagBackgroundColor = tagBackgroundColor,
        _selectedTagBackgroundColor = selectedTagBackgroundColor,
        _tagHeight = tagHeight,
        _tagWidth = tagWidth,
        _tagMinWidth = tagMinWidth,
        super();

  /// tag 文本样式
  final TextStyle? _tagTextStyle;

  /// tag选中文本样式
  final TextStyle? _selectTagTextStyle;

  /// 标签背景色
  final Color? _tagBackgroundColor;

  /// 选中背景色
  final Color? _selectedTagBackgroundColor;

  /// 标签圆角
  final double? _tagRadius;

  /// 标签高度，跟 fixWidthMode 无关
  /// 默认为 34
  final double? _tagHeight;

  /// 标签宽度，且仅在组件设置了固定宽度（fixWidthMode 为 true）时才生效
  /// 默认为 75
  final double? _tagWidth;

  /// 标签最小宽度
  /// 默认为 75
  final double? _tagMinWidth;

  TextStyle get tagTextStyle =>
      _tagTextStyle ??
      TextStyle(color: PPDefaultTheme.instance.colorTextBase, fontSize: 14);

  TextStyle get selectTagTextStyle =>
      _selectTagTextStyle ??
      TextStyle(color: PPDefaultTheme.instance.brandPrimary, fontSize: 14);

  Color get tagBackgroundColor =>
      _tagBackgroundColor ?? PPDefaultTheme.instance.backgroundColor;

  Color get selectedTagBackgroundColor =>
      _selectedTagBackgroundColor ??
      PPDefaultTheme.instance.brandPrimary.withOpacity(0.1);

  double get tagRadius => _tagRadius ?? 8;

  double get tagHeight => _tagHeight ?? 36;

  double get tagWidth => _tagWidth ?? 75;

  double get tagMinWidth => _tagMinWidth ?? 75;

  PPTagTheme copyWith({
    TextStyle? textStyle,
    TextStyle? selectTextStyle,
    double? radius,
    Color? backgroundColor,
    Color? selectedBackgroundColor,
    double? height,
    double? width,
    double? tagMinWidth,
  }) {
    return PPTagTheme(
      tagTextStyle: textStyle ?? _tagTextStyle,
      selectTagTextStyle: selectTextStyle ?? _selectTagTextStyle,
      tagRadius: radius ?? _tagRadius,
      tagBackgroundColor: backgroundColor ?? _tagBackgroundColor,
      selectedTagBackgroundColor:
          selectedBackgroundColor ?? _selectedTagBackgroundColor,
      tagHeight: height ?? _tagHeight,
      tagWidth: width ?? _tagWidth,
      tagMinWidth: tagMinWidth ?? _tagMinWidth,
    );
  }

  PPTagTheme merge(PPTagTheme? other) {
    if (other == null) return this;
    return copyWith(
      textStyle: tagTextStyle.merge(other._tagTextStyle),
      selectTextStyle: selectTagTextStyle.merge(other._selectTagTextStyle),
      radius: other._tagRadius,
      backgroundColor: other._tagBackgroundColor,
      selectedBackgroundColor: other._selectedTagBackgroundColor,
      height: other._tagHeight,
      width: other._tagWidth,
      tagMinWidth: other._tagMinWidth,
    );
  }
}
